import os

import requests
import json

data = {
    "name": "",
    "short_description": "",
    "long_description": "test",
    "area": "医疗",
    "task": "命名实体识别",
}
md = open("demo.md", "r", encoding="utf-8").read()
data["long_description"] = md
base_dir = ["ner_data", 'medical_data']

api_url = "http://cc.qk0.cc:8001/datasets/"
for dir in base_dir:
    files = os.listdir("{}".format(dir))
    for file in files:
        file_name = file.split(".")[0]
        json_file = open("{}/{}".format(dir, file), "rb")
        file_payload = {"train_data": json_file}
        data["name"] = file_name
        data['area'] = "医疗" if dir == "medical_data" else "新闻"
        data["short_description"] = "开源的{} 命名实体识别 数据集".format(file_name)
        rsp = requests.post(api_url, data=data, files=file_payload)
        print(rsp.text, rsp.status_code)
